<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>管理首页 | 统信迁移工具</title>
    <link type="text/css" rel="stylesheet" href="static/css/admin/framework.css" />
	<link href="static/css/admin/style.css" rel="stylesheet" type="text/css" />
    <link type="text/css" rel="stylesheet" href="static/css/admin/main.css" />
	<link rel="stylesheet" href="static/css/admin/bootstrap.min.css">
	<link type="text/css" rel="stylesheet" href="static/css/admin/alert.css" />
	<script src="static/css/admin/jquery.min.js"></script>
</head>
<body>
<div class="page">
	<div class="container">
		<div class="pageHeader" >
			<div class="segment">
				<h3 class="ui dividing header">	
					<img src="static/images/logo.png" style="width: 120px; height: 50px;"/>				
  					<label style="padding-left:320px;font-size:28px;">统信服务器系统迁移软件</label>
				</h3>
			</div>				
		</div>
	<br/>
	<br/>
	<div class="pageHeader">
		<p style="padding-left:470px;font-size:23px;font-family:”思源黑体”;font-weight:bold;">迁移前系统环境检查</p><br/>
		<button id="check_id" type="submit" class="menter_btn_a_a_lf"  onclick="check_environment();" style="margin-left: 530px;text-align: center; line-height: 37px; color:black; font-size:18px;opacity: 1"><style>a{TEXT-DECORATION:none}</style>开始检查</button><br/><br/>
		<div id="env_id1" style="padding-left:450px;display: none;">
			<img src="../static/images/login.gif" width="13" height="13" /><label style="font-size:13px;font-family:”思源黑体”;font-weight:bold;">正在检测当前环境是否适合进行迁移工作......</label>
		</div>
		<div id="env_id2" style="padding-left:330px;display: none;">
			<img src="../static/images/u57.svg" width="13" height="13" /><label style="font-size:13px;font-family:”思源黑体”;font-weight:bold;">当前系统可以进行迁移工作，点击导出 <a onclick="export_test_reports()">迁移检测报告</a>，文件保存在/var/uos-migration/</label>
		</div>
		<div id="env_id3" style="padding-left:215px;display: none;">
			<img src="../static/images/u70.svg" width="13" height="13" /><label style="font-size:13px;font-family:”思源黑体”;font-weight:bold;">当前系统进行迁移可能存在未知的风险，请您确认之后再进行下一步操作，点击导出 <a onclick="export_test_reports()">迁移检测报告</a>，文件保存在/var/uos-migration/</label>
		</div>
		<div id="env_id4" style="padding-left:500px;display: none;">
			<img src="../static/images/u70.svg" width="13" height="13" /><label style="font-size:13px;font-family:”思源黑体”;font-weight:bold;">检查失败，请重新检查</label>
		</div>
		<br/>
		<br/>
		<div class="progress progress-striped active" style="margin-left: 85px;">
			<div id = "pg" class="progress-bar progress-bar-success" role="progressbar"
					 aria-valuenow="0" aria-valuemin="0" aria-valuemax="10"
					 style="width: 0%;">
					<span class="sr-only"></span>
			</div>
		</div>
		<label id="pg_info" style="padding-left:560px;font-size:13px;font-family:”思源黑体”;font-weight:bold;">0%</label>
		</br>
		</br>
		</br>
		<div class="menter_btn_a_lf" >
			<hr style="opacity: 0.1;border: 1px solid #4C4D4E;width:99%;" />
			</br>
			</br>
			<button onclick="close_tool();" data-toggle="modal" data-target="#exampleModal" type="submit" class="menter_btn_a_a_lf" data-locale="Exit" style="text-align: center; line-height: 37px; color:black; font-size:18px;"><style>a{TEXT-DECORATION:none}</style>取消</button>
			<button id="next_id" onclick="save();"  data-locale="Next_Step" type="submit" class="menter_btn_a_a_lf" name="" style="text-align: center; line-height: 37px; color:black; font-size:18px;opacity: 1"><style>a{TEXT-DECORATION:none}</style>下一步</button>
		</div>
    </div>
</div>
<script type="text/javascript" src="static/js/admin/jquery.min.js"></script>
<script type="text/javascript" src="static/js/admin/framework.js"></script>
<script type="text/javascript" src="static/js/admin/jquery.zclip.min.js"></script>
<script type="text/javascript" src="static/js/admin/alert.js"></script>
<script type="text/javascript" src="static/js/admin/save_alert.js"></script>
<script type="text/javascript" src="static/js/admin/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/admin/json.js"></script>
<script>
    function check_environment() {
		progress = setInterval("check_progress()",2000);
	    env = setInterval("check_env()",2000);
    }
    
    function check_env(){
        var check_environment_data_json={"mod":"check_environment"};
        check_environment_data_json.ip="tasks"
        var arr_info = window.location.search;
		check_environment_data_json.kernel_version = arr_info.split(",")[1]
    	document.getElementById('env_id1').style.display = ""
    	document.getElementById('env_id2').style.display = "none"
    	document.getElementById('env_id3').style.display = "none"
    	document.getElementById('env_id4').style.display = "none"
    	document.getElementById('check_id').setAttribute("disabled", true);
    	document.getElementById('check_id').style.opacity = 0.2
    	document.getElementById('next_id').setAttribute("disabled", true);
    	document.getElementById('next_id').style.opacity = 0.2
    	$.ajax({
			async:true,
			type: 'post',
			dataType: 'json',
			url: 'MT_check_environment',
			data: $.toJSON(check_environment_data_json),
			success: function(res) {
				res=$.evalJSON(res);
				if (res.res == -1) {
					document.getElementById('check_id').removeAttribute("disabled");
    				document.getElementById('check_id').style.opacity = 1
    				document.getElementById('env_id1').style.display = "none"
    				document.getElementById('env_id4').style.display = ""
    				clearInterval(progress)
    				clearInterval(env)
				}
				else if (res.res == 2){
					console.log("正在进行环境检查......")
				}
				else if (res.res == 0){
					if (res.data == 1) {
						document.getElementById('check_id').removeAttribute("disabled");
    					document.getElementById('check_id').style.opacity = 1
    					document.getElementById('env_id1').style.display = "none"
    					document.getElementById('env_id3').style.display = ""
						document.getElementById('next_id').removeAttribute("disabled");
						document.getElementById('next_id').style.opacity = 1
						clearInterval(progress)
    					clearInterval(env)
					} else {
						document.getElementById('check_id').removeAttribute("disabled");
    					document.getElementById('check_id').style.opacity = 1
    					document.getElementById('env_id1').style.display = "none"
    					document.getElementById('env_id2').style.display = ""
						document.getElementById('next_id').removeAttribute("disabled");
						document.getElementById('next_id').style.opacity = 1
						clearInterval(progress)
    					clearInterval(env)
					}
				}
			}
        });
    }

	function check_progress() {
		var check_progress_data_json={"mod":"check_progress"};
        check_progress_data_json.ip="tasks"
        var pg = document.getElementById('pg')
        $.ajax({
			async:true,
			type: 'post',
			dataType: 'json',
			url: 'MT_check_progress',
			data: $.toJSON(check_progress_data_json),
			success: function(res) {
				res=$.evalJSON(res);
				pg.style.width=res.progress + "%";
				document.getElementById('pg_info').innerHTML=res.progress + "%";
			}
        });
	}

	function export_test_reports() {
		var export_test_reports_data_json={"mod":"export_migration_reports"};
        export_test_reports_data_json.ip="tasks"
        export_test_reports_data_json.export="UOS_analysis_report"
        export_test_reports_data_json.name="UOS_migration_report"
        var arr_info = window.location.search;
        export_test_reports_data_json.kernel_version = arr_info.split(",")[1]
        export_test_reports_data_json.info = arr_info.split(",")[0].split("=")[1]
		$.ajax({
			async:true,
			type: 'post',
			dataType: 'json',
			url: 'MT_export_migration_reports',
			data: $.toJSON(export_test_reports_data_json),
			success: function(res) {

			}
        });
	}

	function save() {
	    save_alert("确定开始迁移吗？" + "\n" + "迁移工作即将开始，请保证稳定的网络链接，迁移开始后会禁用您的自动更新功能，迁移过程不可逆，请确保您的数据和设置已经[备份]");
	}

	function close_tool() {
        alert("确定关闭迁移软件吗?")
	}

</script>
</body>
</html>
